<?php
namespace Mp\Service\Common;

use Closure;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Support\Facades\View;

class NavManager implements Renderable{

	protected $navs ;

	protected $separator = '>';

	public function __construct(){
		$this->navs = collect();
	}

	public function addNav(...$nav){
		if($nav){
			$this->navs = $this->navs->merge((array)$nav);
		}
		return $this;
		
	}

	public function nav($content){
		if($content instanceof Closure){
			$nav = new Nav();
			call_user_func($content,$nav);
			$this->addNav($nav);
		}else{
			$this->addNav(new Nav($content));
		}
		return $this;
	}

	public function share(){
		View::share('navs', $this->navs);
		return $this;
	}

	public function render(){

		return view('Mp::commons.nav',['navs' => $this->navs ]);
	}

}